package com.foreveross.taskservice.common.model;

import java.io.Serializable;
import java.util.Date;
import java.util.LinkedHashSet;
import java.util.Set;

import com.foreveross.taskservice.common.TaskStatusEnum;
import com.foreveross.taskservice.common.TaskTypeConst;

/**
 * 抽象类任务抓取模型
 * 
 * @author Administrator
 * 
 */
public abstract class AbstractTaskModel implements Serializable {
	private static final long serialVersionUID = 2988954859459722514L;
	/**
	 * 任务id
	 */
	private String id;
	/**
	 * 任务状态，默认等待中==0
	 */
	private int status = TaskStatusEnum.TASK_WATI.getStatus();
	/**
	 * 渠道
	 */
	private AbstractChannelModel channel;
	
	/**
	 * 任务创建时间（与任务类型构建成独立的数据空间）
	 */
	private Date createTime = new Date();
	/**
	 * 开始时间
	 */
	private Date startTime;
	/**
	 * 结束时间
	 */
	private Date endTime;
	/**
	 * 该任务类型（如高铁类型、航空类型等等）（与任务创建时间构建成独立的数据空间）
	 */
	private int taskType=TaskTypeConst.DEFAULT_TASKTYPE;
	/**
	 * 优先级,默认==0
	 */
	private int priority = 0;
	/**
	 * 任务被执行的次数,失败的时候可能会不停的重复，表示任务服务的推送次数
	 */
	private int excuteCount = 0;
	/**
	 * 网页镜像文件大小（byte）
	 */
	private long byteLength = 0;
	/**
	 * 抓取结果集的数量
	 */
	private int crawlCount;
	/**
	 * 是否使用代理IP
	 */
	private boolean useProxyip;
	/**
	 * 时间戳
	 */
	private Set<AbstractAction> actions=new LinkedHashSet<AbstractAction>();
	/**
	 * 添加时间戳
	 * @param actions
	 * @return
	 */
	public boolean addAction(AbstractAction actions){
		return actions==null?false:this.actions.add(actions);
	}
	/**
	 * 清除已有时间戳
	 */
	public void clearActions(){
		this.actions.clear();
	}
	
	
	/**
	 * 返回时间戳轨迹的拷贝
	 * @return
	 */
	public Set<AbstractAction> getActions() {
		return actions;
	}

	@Override
	public boolean equals(Object other) {
		if (this == other) { // 先检查是否其自反性，后比较other是否为空。这样效率高
			return true;
		}
		if (other == null) {
			return false;
		}
		if (!(other instanceof AbstractTaskModel)) {
			return false;
		}
		final AbstractTaskModel ot = (AbstractTaskModel) other;
		if(this.getId()==null || !this.getId().equals(ot.getId())){
			return false;
		}
		return true;
	}

	@Override
	public int hashCode() {
		return this.getId()==null?super.hashCode():this.getId().hashCode();
	}
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	public int getStatus() {
		return status;
	}
	public void setStatus(int status) {
		this.status = status;
	}
	public AbstractChannelModel getChannel() {
		return channel;
	}
	public void setChannel(AbstractChannelModel channel) {
		this.channel = channel;
	}
	public Date getCreateTime() {
		return createTime;
	}
	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}
	public int getTaskType() {
		return taskType;
	}
	public void setTaskType(int taskType) {
		this.taskType = taskType;
	}
	public int getPriority() {
		return priority;
	}
	public void setPriority(int priority) {
		this.priority = priority;
	}
	public int getExcuteCount() {
		return excuteCount;
	}
	public void setExcuteCount(int excuteCount) {
		this.excuteCount = excuteCount;
	}
	public long getByteLength() {
		return byteLength;
	}
	public void setByteLength(long byteLength) {
		this.byteLength = byteLength;
	}
	public int getCrawlCount() {
		return crawlCount;
	}
	public void setCrawlCount(int crawlCount) {
		this.crawlCount = crawlCount;
	}
	public void setActions(Set<AbstractAction> actions) {
		this.actions = actions;
	}
	public Date getStartTime() {
		return startTime;
	}
	public void setStartTime(Date startTime) {
		this.startTime = startTime;
	}
	public Date getEndTime() {
		return endTime;
	}
	public void setEndTime(Date endTime) {
		this.endTime = endTime;
	}
	public boolean isUseProxyip() {
		return useProxyip;
	}
	public void setUseProxyip(boolean useProxyip) {
		this.useProxyip = useProxyip;
	}
	
}
